<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <title>Title</title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <div class="layui-container" style="width:400px;">
                        <form action="" class="layui-form" id="passForm">
                            <div class="layui-form-item">
                                <label class="layui-form-label">旧密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="oldPwd" class="layui-input" lay-verify="required"/>
                                </div>

                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">新密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="newPwd" id="newPwd" class="layui-input" lay-verify="required"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">确认密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="rePass" lay-verify="required|repass" class="layui-input"
                                           verify="required"/>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-block">
                                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="baseSubmit">保存</button>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div style="color:red" class="layui-input-block">
                                    新密码规范规则：字母+数字+特殊字符、至少8位以上
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    var form = layui.form;
    var layer = layui.layer;
    var $ = jquery = layui.jquery;
 	// 强：字母+数字+特殊字符 8位以上
	var pwdStrong =  /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}$/;

    form.verify({
        repass: function (value) {
            var pass = $("#newPwd").val();
            if (pass != value) {
                return '两次输入的密码不一致';
            }

            if (!pwdStrong.test(pass)) {
				layer.msg('新密码不符合规范，规则：字母+数字+特殊字符、至少8位以上');
				return false;
			}

        }
    })
    form.on('submit(baseSubmit)', function (data) {
        CoreUtil.sendPut("/sys/user/pwd", data.field, function (res) {
            layer.msg("密码已经变更请重新登录", {time: 2000}, function () {
                top.window.location.href = "/index/login";
            });
        });

        return false;
    })
</script>
</body>
</html>